﻿using System;
using System.Collections.Generic;

namespace modul3
{
    class cSysIndexMy
    {
        public cSysIndexMy(string pa_sNazov, kkIndexType pa_kTyp, bool pa_bUnique, List<int> pa_aColumns, int pa_iTabulka, int pa_iId)
        {
            this.iId = pa_iId;
            this.kTyp = pa_kTyp;
            this.iTabulka = pa_iTabulka;
            this.bUnique = pa_bUnique;
            this.aColumns = pa_aColumns;
            if (pa_sNazov.Equals(""))
            {
                sNazov = this.VygenerujNazov();
            }
            else
            {
                sNazov = pa_sNazov + "_" + pa_iId.ToString();
            }
        }

        private int piId;
        /// <summary>
        /// unikatne id (v ramci celeho systemu - vsetkych databaz)
        /// kazde dalsie je o jedna vacsie.
        /// </summary>
        public int iId
        {
            get { return piId; }
            set { piId = value; }
        }

        private string psNazov;
        /// <summary>
        /// Nazov indexu
        /// </summary>
        public string sNazov
        {
            get { return psNazov; }
            set { psNazov = value; }
        }

        private kkIndexType pkTyp;
        /// <summary>
        /// Typ indexu Bitmap index, Dense index, Sparse index
        /// </summary>
        public kkIndexType kTyp
        {
            get { return pkTyp; }
            set { pkTyp = value; }
        }

        private int piTabulka;
        /// <summary>
        /// Cislo indexu
        /// </summary>
        public int iTabulka
        {
            get { return piTabulka; }
            set { piTabulka = value; }
        }

        private bool pbUnique;
        public bool bUnique
        {
            get { return pbUnique; }
            set { pbUnique = value; }
        }

        private List<int> paColumns;
        /// <summary>
        /// cisla stlpcov na ktorych je index
        /// </summary>
        public List<int> aColumns
        {
            get { return paColumns; }
            set { paColumns = value; }
        }

        /// <summary>
        /// automaticky vygeneruje nazov podla nazvu tabuly a typu indexu - napriklad zapisane_predmety_pk, zapisane_predmety_1
        /// </summary>
        /// <returns></returns>
        private string VygenerujNazov()
        {
            string sNovyNazov = "i_" + iTabulka.ToString() + "_" + kTyp.ToString() + "_" + iId;
            if (bUnique)
            {
                sNovyNazov += "_unique";
            }
            return sNovyNazov;
        }

        override
        public string ToString()
        {
            string stlpce = "";
            foreach (int col in aColumns)
            {
                stlpce += col.ToString() + " ";
            }
            return sNazov + " (" + stlpce + ")";
        }
    }
}
